GBML manual / Maths

roll_real

A real number between lo and hi, both ends included - roll_real(0, 360) is any direction, roll_real(0.8, 1.2) a small wobble either side of 1.

Syntax

roll_real(lo, hi) -> real

Arguments

NameType
loreal
hireal

Returns

real

Description

A real number somewhere between lo and hi, with both ends included - roll_real(0, 360) is any direction at all, and roll_real(0.8, 1.2) is a small wobble either side of 1, the sort of thing a scale or a speed multiplier wants.

The range works exactly the way roll_int's does; the only difference between the two is the kind of number you get back. Reach for this one whenever the value feeds something continuous - an angle, a speed, a scale - and for roll_int whenever it is a count, an index or a frame number.

Example

direction = roll_real(0, 360);
speed = roll_real(0.4, 1.2);

Throws a spark off in any direction at all, at a speed that differs every time. Both ends of both ranges are reachable, so 0 and 360 are as likely as anything between them - the same direction twice over, which is exactly right for an angle.

Both ends really are included

"Included" here is exact, not almost. Numbers are 20.12 fixed-point, so there is a finite list of values between lo and hi, and hi is one of them - a reachable value, not a limit approached and never touched. That matters because the half-open sibling other languages ship is where the off-by-one lives: here roll_int(0, 5) and roll_real(0, 5) describe the same span, and the only difference is the kind of number handed back.

A range written the wrong way round behaves as it does in roll_int - the same set of numbers, read the other way.

Rolls repeat, on purpose

Two runs of the same ROM roll the same numbers in the same order, unless something calls roll_reseed. See roll_int for why that is the default, what it means across a save, and which two streams in the engine are deliberately not this one.

On the GBA

The same range rule as roll_int, on purpose: roll_int(0, 5) and roll_real(0, 5) mean the same span and differ only in the kind of number handed back, so there is no half-open sibling to remember. "Both ends included" is exact here too - hi is a reachable value, one of the fixed-point steps between the two ends, not a limit approached. One draw per call, from the same stream roll_int uses.

See also: roll_introll_chanceroll_reseedroll_one_of